package com.sz.app.oss.api.logistics.order;

import com.google.common.collect.Lists;
import com.sz.app.oss.constants.MessagesCodes;
import com.sz.app.oss.constants.Permissions;
import com.sz.biz.app.web.BaseController;
import com.sz.biz.common.constants.CommCodes;
import com.sz.biz.common.constants.ErrorCodes;
import com.sz.biz.common.customer.entity.CusUser;
import com.sz.biz.common.customer.service.CustomerUserService;
import com.sz.biz.common.utils.OrderMake;
import com.sz.biz.logistics.ord.constants.OrderConstants;
import com.sz.biz.logistics.ord.dto.*;
import com.sz.biz.logistics.ord.entity.OrdOrder;
import com.sz.biz.logistics.ord.entity.OrdSubOrder;
import com.sz.biz.logistics.ord.entity.OrderStatus;
import com.sz.biz.logistics.ord.service.OrdOrderService;
import com.sz.biz.logistics.ord.service.OrdOrderStatusCodeService;
import com.sz.biz.logistics.ord.service.OrdSubOrderService;
import com.sz.biz.pay.constants.PayStatus;
import com.sz.common.base.dto.CommonModel;
import com.sz.common.base.dto.QueryParams;
import com.sz.common.base.dto.ResultDto;
import com.sz.common.base.exception.Exceptions;
import com.sz.common.base.logger.Logger;
import com.sz.common.base.utils.DateUtils;
import com.sz.common.base.utils.StringUtils;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * Function: 订单 controller <br>
 * Author: hpeng.wang <br>
 * Date: 2017-03-31 14:28:00
 */
@RestController
@RequestMapping("/api/v1/order/products")
@Api(description = " ", tags = "036-001、订单")
public class OrdOrderController extends BaseController {
    private final Logger logger = Logger.getLogger(this.getClass());
    @Autowired
    private OrdOrderService service;
    @Autowired
    private OrdSubOrderService subOrderService;
    @Autowired
    private CustomerUserService cusUserService;
    @Autowired
    private OrdOrderStatusCodeService statusCodeService;

    /**
     * 新增.
     */
    @ApiOperation(value = "新增", notes = "新增订单<br>权限：" + Permissions.BIZ_MGT_ORD_ORDER, position = 1)
    @RequestMapping(value = "", method = {RequestMethod.POST})
    @RequiresPermissions(Permissions.BIZ_MGT_ORD_ORDER)
    public ResultDto save(@RequestBody @ApiParam(value = "要保存的数据", required = true) @Validated OrdOrderDto dto) {
        dto.setId(null);//保存时忽略id
        dto.setType(OrderConstants.OrderPlatform.ORDER_OPERATOR);//运营系统的订单
        String orderNo = service.saveOrderDto(dto);
        String messagesCode = MessagesCodes.MODULE_ORDER_PRODUCT;
        if (dto.getOrderStatus() == OrderStatus.DRAFT) {
            messagesCode = MessagesCodes.MODULE_ORDER_PRODUCT_DRAFT;
        } else if (dto.getOrderStatus() == OrderStatus.COMMITED ||dto.getOrderStatus() == OrderStatus.ACCEPT) {
            messagesCode = MessagesCodes.MODULE_ORDER_PRODUCT_COMMITED;
        }
        ResultDto result = getOperateSuccessDto(messagesCode);
        result.setData(orderNo);
        return result;
    }

    /**
     * 批量删除
     *
     * @param ids 要删除的id集合
     * @return 操作结果
     */
    @ApiOperation(value = "删除", notes = "根据指定orderNo集合删除数据<br>权限：" + Permissions.BIZ_MGT_ORD_ORDER, httpMethod = "POST", position = 2)
    @RequestMapping(value = "/deletions", method = {RequestMethod.POST})
    @RequiresPermissions(Permissions.BIZ_MGT_ORD_ORDER)
    public ResultDto batchDelete(@RequestBody @ApiParam(value = "要删除的orderNo集合", required = true) List<String> ids) {
        service.batchDeleteByOrderNos(ids);
        ResultDto dto = getDeleteSuccessDto(MessagesCodes.MODULE_ORDER_PRODUCT);
        return dto;
    }

    /**
     * 修改.
     */
    @RequestMapping(value = "{orderNo}", method = {RequestMethod.POST})
    @ApiOperation(value = "修改", notes = "修改订单数据<br>权限：" + Permissions.BIZ_MGT_ORD_ORDER, position = 3)
    @RequiresPermissions(Permissions.BIZ_MGT_ORD_ORDER)
    public ResultDto update(@RequestBody @Validated OrdOrderDto dto) {
        //判断订单编号不为空
        if (org.apache.commons.lang3.StringUtils.isEmpty(dto.getOrderNo())) {
            throw Exceptions.bizException(ErrorCodes.ERROR_COMMON, "订单号不能为空");
        }
        service.updateByDto(dto, CommCodes.OPERATOR);
        String messagesCode = MessagesCodes.MODULE_ORDER_PRODUCT;
        ResultDto result;
        if (dto.getOrderStatus() == OrderStatus.DRAFT) {
            messagesCode = MessagesCodes.MODULE_ORDER_PRODUCT_DRAFT;
            result = getOperateSuccessDto(messagesCode);
        } else if (dto.getOrderStatus() == OrderStatus.COMMITED) {
            messagesCode = MessagesCodes.MODULE_ORDER_PRODUCT_COMMITED;
            result = getOperateSuccessDto(messagesCode);
        } else {
            result = getUpdateSuccessDto(messagesCode);
        }
        return result;
    }


    /**
     * 根据subOrderNo查询数据
     *
     * @param subOrderNo 子订单的subOrderNo
     * @return 查询到的单条子订单
     */
    @RequestMapping(value = "/sub/{subOrderNo}", method = RequestMethod.GET)
    @ApiOperation(value = "查询_subOrderNo", notes = "根据subOrderNo获取到的子订单", position = 4)
    public ResultDto findBySubOrderNo(@ApiParam(value = "子订单subOrderNo", required = true) @PathVariable String subOrderNo) {
        OrdSubOrderDto dto = subOrderService.findDtoBySubOrderNo(subOrderNo);
        ResultDto result = new ResultDto();
        result.setData(dto);
        return result;
    }


    /**
     * 根据orderNo查询数据
     *
     * @param orderNo 订单的orderNo
     * @return 查询到的单条订单
     */
    @RequestMapping(value = "/{orderNo}", method = RequestMethod.GET)
    @ApiOperation(value = "查询_orderNo", notes = "根据orderNo获取到的订单", position = 5)
    public ResultDto findByOrderNo(@ApiParam(value = "订单orderNo", required = true) @PathVariable String orderNo) {
        OrdOrderDto orderDto = service.findDtoByOrderNo(orderNo);
        ResultDto result = new ResultDto();
        result.setData(orderDto);
        return result;
    }


    @RequestMapping(value = "/service/{orderNo}", method = RequestMethod.GET)
    @ApiOperation(value = "查询_findServiceByOrderNo", notes = "根据orderNo获取订单已选择的所有服务，并且带顺序", position = 6)
    public ResultDto findServiceByOrderNo(@ApiParam(value = "订单orderNo", required = true) @PathVariable String orderNo) {
        List<CommonModel> serviceList = service.findServiceByOrderNo(orderNo);
        ResultDto result = new ResultDto();
        result.setData(serviceList);
        return result;
    }


    /**
     * 根据条件获取数据集合
     *
     * @param q         参数信息
     * @param pageIndex 哪页
     * @param pageSize  分页大小
     * @param waybillNo 订单编号
     * @param sort      排序字段的名称
     * @param asc       true asc false desc
     * @return 查询的数据集合
     */
    @ApiOperation(value = "查询", notes = "根据指定条件获取数据集合", position = 7)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "q", value = "模糊查询参数", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "分页", dataType = "int", paramType = "query", defaultValue
                    = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数,max<2000", dataType = "int", paramType = "query",
                    defaultValue = "10"),
            @ApiImplicitParam(name = "sort", value = "排序的字段", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "waybillNo", value = "运单编号", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "externalNo", value = "客户单号", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "asc", value = "排序方式", dataType = "boolean", paramType = "query", defaultValue =
                    "true")
    })
    @RequestMapping(value = "", method = RequestMethod.GET)
    @RequiresPermissions(value = {Permissions.BIZ_MGT_ORD_ORDER,Permissions.BIZ_MGT_RPT_DASHBOARD},logical = Logical.OR)
    public ResultDto find(@RequestParam(required = false) String q,
                          @RequestParam(required = false, defaultValue = "1") int pageIndex,
                          @RequestParam(required = false, defaultValue = "10") int pageSize,
                          @RequestParam(required = false) String waybillNo,
                          @RequestParam(required = false) String externalNo,
                          @RequestParam(required = false, defaultValue = "") String startEffectTime,
                          @RequestParam(required = false, defaultValue = "") String endEffectTime,
                          @RequestParam(required = false) OrderStatus orderStatus,
                          @RequestParam(required = false) String payStatus,
                          @RequestParam(required = false) String customerId,
                          @RequestParam(required = false) String cusUserId,
                          @RequestParam(required = false) String sort,
                          @RequestParam(required = false, defaultValue = "true") Boolean asc
    ) {
        q = StringUtils.replaceSqlPattern(q);
        QueryParams qp = new QueryParams(pageSize, pageIndex, q, sort, asc);
        try {
            if (!ObjectUtils.isEmpty(waybillNo)) {
                qp.put("waybillNo", waybillNo.trim());
            } else if (!ObjectUtils.isEmpty(externalNo)) {
                qp.put("externalNo", externalNo.trim());
            } else {
                if (!ObjectUtils.isEmpty(startEffectTime) || !ObjectUtils.isEmpty(endEffectTime)) {
                    //开始时间
                    if (ObjectUtils.isEmpty(startEffectTime)) {
                        qp.put("startEffectTime", DateUtils.convertToDate("1970-01-01", DateUtils.FORMAT_SIMPLE));
                    } else {
                        qp.put("startEffectTime", DateUtils.convertToDate(startEffectTime, DateUtils.FORMAT_DETAIL));
                    }
                    //结束时间
                    if (ObjectUtils.isEmpty(endEffectTime)) {
                        qp.put("endEffectTime", DateUtils.convertToDate("2100-01-01", DateUtils.FORMAT_SIMPLE));
                    } else {
                        qp.put("endEffectTime", DateUtils.convertToDate(endEffectTime, DateUtils.FORMAT_DETAIL));
                    }
                }


                if (!ObjectUtils.isEmpty(customerId)) {
                    qp.put("customerId", customerId);
                }
                if (!ObjectUtils.isEmpty(cusUserId)) {
                    qp.put("cusUserId", cusUserId);
                }
            }
            if (!ObjectUtils.isEmpty(orderStatus)) {
                qp.put("orderStatus", orderStatus);
            }
            if (!ObjectUtils.isEmpty(payStatus)) {
                PayStatus payEnum = PayStatus.valueOfEnum(payStatus);
                qp.put("payStatus", payEnum);
            }

        } catch (Exception e) {
            logger.error("", e);
            e.printStackTrace();
        }
        ResultDto result = service.findDtoByParam(qp);
        return result;
    }

    /**
     * 获取订单的支付状态数据
     *
     * @return
     */
    @RequestMapping(value = "/paystatus", method = RequestMethod.GET)
    @ApiOperation(value = "获取订单支付状态数据", notes = "获取订单支付状态数据")
    public ResultDto getOrderAllPayStatus() {
        List<CommonModel> list = service.getOrderPayStatus();
        ResultDto result = new ResultDto();
        result.setData(list);
        return result;
    }

    /**
     * 获取订单的支付状态数据
     *
     * @return
     */
    @RequestMapping(value = "/feeInfo/{waybillNo}", method = RequestMethod.GET)
    @ApiOperation(value = "获取订单费用数据", notes = "获取订单费用数据")
    public ResultDto getOrderAFeeInfo(@ApiParam(value = "订单waybillNo", required = true) @PathVariable String waybillNo) {
        OrdOrderFeePayDto ordOrderFeePayDto = service.findOrderFeeInfo(waybillNo);
        ResultDto result = new ResultDto();
        result.setData(ordOrderFeePayDto);
        return result;
    }


    /**
     * 根据waybillNo查询物流信息
     *
     * @param waybillNo 订单的waybillNo
     * @return 查询到的物流信息
     */
    @RequestMapping(value = "/track/{waybillNo}", method = RequestMethod.GET)
    @ApiOperation(value = "查询物流_waybillNo", notes = "根据waybillNo获取订单的物流信息", position = 8)
    public ResultDto findTrackByWaybillNo(@ApiParam(value = "订单waybillNo", required = true) @PathVariable String waybillNo) {
        List<Integer> rankList = statusCodeService.getRanks();
        Map<String, List<OrdOrderTrackingShowDto>> orderTrackingMap = service.findTrackByWaybillNo(rankList, waybillNo);
        ResultDto result = new ResultDto();
        result.setData(orderTrackingMap);
        return result;
    }


    /**
     * 获取所有订单的状态数据
     *
     * @return
     */
    @RequestMapping(value = "/orderstatus", method = RequestMethod.GET)
    @ApiOperation(value = "获取所有订单的状态数据", notes = "获取订单的所有状态数据", position = 9)
    public ResultDto getAllOrderStatus() {
        List<CommonModel> list = service.getAllOrderStatus();
        ResultDto result = new ResultDto();
        result.setData(list);
        return result;
    }

    /**
     * 将订单状态从已提交变为已受理状态
     *
     * @param waybillNo
     * @return
     */
    @RequestMapping(value = "/{waybillNo}/status", method = RequestMethod.POST)
    @ApiOperation(value = "将已提交的订单状态改为已经受理", notes = "将订单状态变为已受理", position = 10)
    public ResultDto updateStatusToAccept(@ApiParam(value = "订单waybillNo", required = true) @PathVariable String waybillNo) {
        String orderNo = service.findOrderNoByWaybillNo(waybillNo);
        service.generateBillData(orderNo);
        ResultDto result = new ResultDto();
        result.setMsg("订单状态已经变为已受理");
        result.setErrorCode(0);
        return result;
    }
    @RequestMapping(value = "/pay/{waybillNo}", method = RequestMethod.POST)
    @ApiOperation(value = "将订单变成已支付", notes = "将订单变成已支付", position = 10)
    public ResultDto payOrder(@ApiParam(value = "订单waybillNo", required = true) @PathVariable String waybillNo) {
        String orderNo = service.findOrderNoByWaybillNo(waybillNo);
        service.payOrder(orderNo);
        ResultDto result = new ResultDto();
        result.setMsg("订单状态已经支付");
        result.setErrorCode(0);
        return result;
    }

    /**
     * 将订单状态从草稿变为已提交状态.批量提交
     *
     * @param orderNos
     * @return
     */
    @RequestMapping(value = "/status/commit", method = RequestMethod.POST)
    @ApiOperation(value = "将草稿的订单状态改为已提交状态", notes = "将订单状态变为已提交", position = 11)
    public ResultDto updateCommitedByOrderNos(@ApiParam(value = "订单orderNo", required = true) @RequestBody List<String> orderNos) {
        service.updateCommitedByOrderNos(orderNos);
        ResultDto result = new ResultDto();
        result.setMsg("订单状态已经变为已提交");
        result.setErrorCode(0);
        return result;
    }

    /**
     * 将订单状态从已提交变为已受理状态
     *
     * @param orderNos
     * @return
     */
    @RequestMapping(value = "/status/accept", method = RequestMethod.POST)
    @ApiOperation(value = "将已提交的订单状态改为已受理状态", notes = "将订单状态变为已受理")
    public ResultDto updateAcceptByOrderNos(@ApiParam(value = "订单orderNo", required = true) @RequestBody List<String> orderNos) {
       service.updateAcceptByOrderNos(orderNos);
        return getAcceptSuccessDto(MessagesCodes.MODULE_ORDER_PRODUCT);

    }

    @RequestMapping(value = "/{waybillNo}/services", method = RequestMethod.GET)
    @ApiOperation(value = "根据订单编号获取服务商信息", position = 12)
    public ResultDto getServicesByOrderNo(@ApiParam(value = "订单waybillNo", required = true) @PathVariable String waybillNo) {
        String orderNo = service.findOrderNoByWaybillNo(waybillNo);
        List<ServiceForOrderDto> list = service.getServiceDtos(orderNo);
        ResultDto result = new ResultDto();
        result.setData(list);
        return result;
    }

    @RequestMapping(value = "/{waybillNo}/subOrders", method = RequestMethod.GET)
    @ApiOperation(value = "根据订单编号获取子订单", position = 13)
    public ResultDto getSubOders(@ApiParam(value = "订单waybillNo", required = true) @PathVariable String waybillNo) {
        String orderNo = service.findOrderNoByWaybillNo(waybillNo);
        List<String> orderNos = Lists.newArrayList();
        orderNos.add(orderNo);
        List<OrdSubOrder> list = subOrderService.findByOrderNos(orderNos);
        ResultDto result = new ResultDto();
        result.setData(list);
        return result;
    }


    /**
     * 根据订单号返回订单客户的名字与电话号码
     *
     * @param waybillNo 订单号
     * @return　校验的结果
     */
    @ApiOperation(value = "根据非草稿状态的订单号返回订单客户的名字与电话号码", notes = "根据非草稿状态的订单号返回订单客户的名字与电话号码", position = 14)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNo", value = "订单", required = true, dataType = "string", paramType = "query")})
    @RequestMapping(value = "/findcususerbyorderno", method = {RequestMethod.GET})
    public ResultDto findCusUserByOrderNo(@RequestParam String waybillNo) {
        String orderNo = service.findOrderNoByWaybillNo(waybillNo);
        OrdOrderCusUserDto dto = service.findCusUserByOrderNo(orderNo);

        return new ResultDto(dto);
    }

    @ApiOperation(value = "自动获取客户订单号", notes = "自动获取客户订单号<br>", httpMethod = "GET", position = 15)
    @RequestMapping(value = "/cusorderno/{cusUserId}", method = {RequestMethod.GET})
    @RequiresPermissions(Permissions.BIZ_MGT_ORD_ORDER)
    public ResultDto getExternalNo(@ApiParam(value = "账号id", required = true) @PathVariable Integer cusUserId) {
        if (cusUserId == 0) {
            throw Exceptions.bizException(ErrorCodes.ERROR_COMMON, "账号id不正确");
        } else {
            CusUser cusUser = cusUserService.findById(cusUserId);
            if (null == cusUser) {
                throw Exceptions.bizException(ErrorCodes.ERROR_COMMON, "客户异常");
            }
            String cusOrderNo = OrderMake.generateCusExternalNo();
            ResultDto result = new ResultDto();
            result.setData(cusOrderNo);
            return result;
        }
    }


    @ApiOperation(value = "检查客户填写的客户订单号是否已经存在", notes = "检查客户填写的客户订单号是否已经存在<br>", httpMethod = "POST", position = 16)
    @RequestMapping(value = "/cusorderno/{cusUserId}/{externalNo}/{id}", method = {RequestMethod.POST})
    @RequiresPermissions(Permissions.BIZ_MGT_ORD_ORDER)
    public ResultDto checkExternalNo(@ApiParam(required = true) @PathVariable String externalNo, @ApiParam(value = "账号id", required = true) @PathVariable Integer cusUserId, @PathVariable int id) {
        ResultDto result = new ResultDto();
        if (org.apache.commons.lang3.StringUtils.isBlank(externalNo)) {
            throw Exceptions.bizException(ErrorCodes.ERROR_COMMON, "参数不能为空");
        }
        if (cusUserId == 0) {
            throw Exceptions.bizException(ErrorCodes.ERROR_COMMON, "账户id不正确");
        } else {
            CusUser cusUser = cusUserService.findById(cusUserId);
            if (cusUser == null) {
                //账号不存在
                throw Exceptions.bizException(ErrorCodes.ERROR_COMMON, "账号异常");
            }
            OrdOrder ordOrder = service.findByExternalNoAndCustomerId(externalNo, cusUser.getRefCustomerId(), id);
            if (!ObjectUtils.isEmpty(ordOrder)) {
                result.setData(ordOrder);
            }
        }
        return result;
    }

    @ApiOperation(value = "给选定的订单发送消息", notes = "给选定的订单发送消息", httpMethod = "POST", position = 17)
    @RequestMapping(value = "/cusorderno/message", method = {RequestMethod.POST})
    @RequiresPermissions(Permissions.BIZ_MGT_ORD_ORDER)
    public ResultDto sendMessage(@ApiParam(required = true) @RequestBody List<String> orders) {
        if (orders == null || orders.size() < 0) {
            throw Exceptions.bizException(ErrorCodes.ERROR_COMMON, "订单ID不能为空");
        }
        service.sendOrderStatusMessage(orders);
        ResultDto resultDto = getOperateSuccessDto(com.sz.biz.common.constants.MessagesCodes.MODULE_ORDER_MESSAGE_SEND_SUCCESS);
        return resultDto;
    }

    @ApiOperation(value = "判断订单中哪些订单无法发送消息", notes = "判断订单是否能够发送消息", httpMethod = "POST", position = 19)
    @RequestMapping(value = "/cusorderno/check", method = {RequestMethod.POST})
    @RequiresPermissions(Permissions.BIZ_MGT_ORD_ORDER)
    public ResultDto checkOrderMessage(@ApiParam(required = true) @RequestBody List<String> orders) {
        if (orders == null || orders.size() < 0) {
            throw Exceptions.bizException(ErrorCodes.ERROR_COMMON, "订单ID不能为空");
        }
        OrderMessageList orderMessageList = service.getOrderMessageList(orders);
        ResultDto resultDto = new ResultDto();
        resultDto.setData(orderMessageList);
        return resultDto;
    }


    @ApiOperation(value = "订单查询接口", notes = "订单查询接口", position = 18)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "分页", dataType = "int", paramType = "query", defaultValue
                    = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数,max<2000", dataType = "int", paramType = "query",
                    defaultValue = "10"),
            @ApiImplicitParam(name = "sort", value = "排序的字段", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "keyword", value = "订单编号或者客户单号的关键字,精确查询", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "cusUserId", value = "客户账号id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "asc", value = "排序方式", dataType = "boolean", paramType = "query", defaultValue =
                    "true")
    })
    @RequestMapping(value = "/search/list", method = RequestMethod.GET)
    @RequiresPermissions(Permissions.BIZ_MGT_ORD_ORDER)
    public ResultDto searchOrderList(
            @RequestParam(required = false, defaultValue = "1") int pageIndex,
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @RequestParam(required = false) String keyword,
            @RequestParam String startTime,
            @RequestParam String endTime,
            @RequestParam(required = false) OrderStatus orderStatus,
            @RequestParam(required = false) Integer cusUserId,
            @RequestParam(required = false) String sort,
            @RequestParam(required = false, defaultValue = "true") Boolean asc
    ) {
        keyword = StringUtils.replaceSqlPattern(keyword);
        QueryParams qp = new QueryParams(pageSize, pageIndex, null, sort, asc);
        if (!ObjectUtils.isEmpty(keyword)) {
            qp.put("keyword", keyword.trim());
        } else {
            try {
                //开始时间
                if (!ObjectUtils.isEmpty(startTime)) {
                    qp.put("startTime", DateUtils.convertToDate(startTime, DateUtils.FORMAT_DETAIL));
                }
                //结束时间
                if (!ObjectUtils.isEmpty(endTime)) {
                    qp.put("endTime", DateUtils.convertToDate(endTime, DateUtils.FORMAT_DETAIL));
                }
            } catch (ParseException e) {
                throw Exceptions.bizException(com.sz.biz.logistics.constants.ErrorCodes.ERROR_ARGUMENT_ILLEGAL, "startTime or endTime ");
            }
            if (!ObjectUtils.isEmpty(orderStatus)) {
                qp.put("orderStatus", orderStatus);
            }
            if (!ObjectUtils.isEmpty(cusUserId)) {
                CusUser cusUser = cusUserService.findById(cusUserId);
                if (null == cusUser) {
                    throw Exceptions.bizException(com.sz.biz.logistics.constants.ErrorCodes.ERROR_ARGUMENT_ILLEGAL, cusUser);
                }

                if (cusUser.getIsSystem()) {
                    //主账户，不需要传递cusUserId
                    qp.put("customerId", cusUser.getRefCustomerId());
                } else {
                    qp.put("cusUserId", cusUserId);
                }
            }
        }


        ResultDto result = service.findSearchDtoByParam(qp);
        return result;
    }


    /**
     * 根据订单号获取订单服务信息
     *
     * @param orderNo 订单的orderNo
     * @return 订单服务信息
     */
    @RequestMapping(value = "/order/serviceinfo/{orderNo}", method = RequestMethod.GET)
    @ApiOperation(value = "根据订单号获取订单服务信息_orderNo", notes = "根据orderNo获取到的订单", position = 5)
    @RequiresPermissions(Permissions.BIZ_MGT_ORD_ORDER)
    public ResultDto findOrderServiceInfo(@ApiParam(value = "订单orderNo", required = true) @PathVariable String orderNo) {
        List<OrdOrderServiceInfoDto> infoDtoList = service.findOrderServiceInfo(orderNo, true);
        ResultDto result = new ResultDto();
        result.setData(infoDtoList);
        return result;
    }


}
